﻿
// 格式化日期
Date.prototype.format = function(formatter) {
    if (!formatter || formatter == "") {
        formatter = "yyyy-MM-dd";
    }
    var year = this.getFullYear().toString();
    var month = (this.getMonth() + 1).toString();
    var day = this.getDate().toString();
    var yearMarker = formatter.replace(/[^y|Y]/g, '');
    if (yearMarker.length == 2) {
        year = year.substring(2, 4);
    }
    var monthMarker = formatter.replace(/[^m|M]/g, '');
    if (monthMarker.length > 1) {
        if (month.length == 1) {
            month = "0" + month;
        }
    }
    var dayMarker = formatter.replace(/[^d]/g, '');
    if (dayMarker.length > 1) {
        if (day.length == 1) {
            day = "0" + day;
        }
    }
    return formatter.replace(yearMarker, year).replace(monthMarker, month).replace(dayMarker, day);
}
// 获取首月第一天
function GetFirstDayOfMonth() {
    var date = new Date();
    var year = date.getFullYear();
    var month = (date.getMonth() + 1).toString();
    if (month.length == 1) {
        month = "0" + month;
    }
    return year + "-" + month + "-01";
}

// 校验日期查询条件
function vaildeFilter() {
    //校验条件
    if (document.getElementById("txtBgnDate").value == "") {
        alert("‘起始日期’不能为空！");
        return false;
    }

    if (document.getElementById("txtEndDate").value == "") {
        alert("‘截止日期’不能为空！");
        return false;
    }

    if (document.getElementById("txtBgnDate").value > document.getElementById("txtEndDate").value) {
        alert("‘截止日期’必须大于等于‘起始日期’！");
        return false;
    }

    return true;
}


//导出excel
//参数:
//   strQtobj 显示这个对象里面的内容
function ExportExcel(strQtobj) {
    try {
        var obj;
        if (strQtobj != undefined && strQtobj != "") {
            obj = document.getElementById(strQtobj);
        }
        else {
            obj = document.getElementById("objTable");
        }
        var regEx, regEx1;
        var strHTML;
        var regHTML;
        
        var divExcel = document.createElement("div");
        divExcel.innerHTML = obj.outerHTML;
        obj = divExcel.children(0);
        //删除固定行
        obj.deleteRow(0);
        //设置导出TABLE的样式
        obj.style.fontSize = "10pt";
        obj.style.tableLayout = "fixed";
        // 遍历行设置样式、重置colspan、格式化超链接内容
        var rowCount = obj.rows.length; //所有行数
        var colCount, i, j;
        // 为每列第一个单元格命名
        for (i = 0; i < rowCount; i++) {
            if (obj.rows[i].header == "1") {
                obj.rows[i].style.height = "22px";
                obj.rows[i].style.backgroundColor = "#CCCCCC";

                colCount = obj.rows[i].cells.length;
                for (j = 0; j < colCount; j++) {
                    obj.rows[i].cells[j].style.textAlign = "center";
                    obj.rows[i].cells[j].colSpan = (obj.rows[i].cells[j].colSpan + 1) / 2;
                }
            } else {
                obj.rows[i].style.height = "22px";
                obj.rows[i].style.backgroundColor = "#EEEEEE";
                obj.rows[i].cells[0].innerHTML = obj.rows[i].cells[0].innerText;
            }
        }
        regHTML = obj.outerHTML;
        //过滤掉其中的Image图片
        regEx = /<td.*<img.*<\/td>/gi;
        regEx1 = /<td><\/td>/gi;
        regHTML = regHTML.replace(regEx, "").replace(regEx1, "");
        
        strHTML = '<META http-equiv="Content-Type" content="text/html;charset=gb2312">';

        strHTML += regHTML;

        MyZipLib.SaveToFile(strHTML);
        
        
    }
    catch (e)
    { }


}
